home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / wzun11sr.zip / ACTION.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  6KB  |  182 lines

  1. #include <windows.h>    /* required for all Windows applications */
  2. #include <assert.h>    /* required for all Windows applications */
  3. #include "wizunzip.h"                /* specific to this program              */
  4. #include "unzip.h"     
  5.  
  6. /* Action.c module of WizUnzip.
  7.  * Author: Robert A. Heath, 1992
  8.  * I, Robert Heath, place this source code module in the public domain.
  9.  */
  10. char NoMemoryMsg[] = 
  11.             "Insufficient memory for this operation!";
  12.  
  13. int    MsWinDoAll;
  14.  
  15. BOOL bIconSwitched = FALSE;    /* set true after 1st valid action    */
  16.  
  17. /* Get Selection Count returns a count of the selected 
  18.  * list box items. If the count is  greater than zero, it also returns
  19.  * a pointer to a locked list in local memory of the item nos.
  20.  * and their local memory handle.
  21.  * A value of -1 indicates an error.
  22.  */
  23. int GetLBSelCount(HWND hListBox, int **ppnSelItems)
  24. {
  25. int    nSelCount = (int)SendMessage(hListBox, LB_GETSELCOUNT, 0, 0L);
  26. int    nRetrieved;
  27.  
  28.     if (nSelCount)
  29.     {
  30.         *ppnSelItems = (int *)LocalAlloc(LMEM_FIXED, nSelCount * sizeof(int));
  31.  
  32.         assert(*ppnSelItems); /* DEBUG */
  33.         if (!*ppnSelItems)
  34.         {
  35.             return(-1);
  36.         }
  37.         nRetrieved = (int)SendMessage(hWndList, LB_GETSELITEMS, nSelCount, (LONG)(LPSTR)*ppnSelItems);
  38.         assert(nRetrieved == nSelCount);
  39.         if (nRetrieved != nSelCount)
  40.         {
  41.             LocalFree((HANDLE)*ppnSelItems);
  42.             return(-1);
  43.         }
  44.     }
  45.     return(nSelCount);
  46. }
  47.  
  48. /* Re-select listbox contents from given list. The pnSelItems is a
  49.  * list containing the indices of those items selected in the listbox.
  50.  * This list was probably created by GetLBSelCount() above.
  51.  */
  52. void ReselectLB(HWND hListBox, int    nSelCount, int *pnSelItems)
  53. {
  54. int i;
  55.  
  56.     for (i = 0; i < nSelCount; i++)
  57.     {
  58.         SendMessage(hListBox, LB_SETSEL, TRUE, MAKELONG(pnSelItems[i],0));
  59.     }
  60. }
  61.  
  62.  
  63. /* Action is called on double-clicking, or selecting one of the 3
  64.  * main action buttons. The action code is the action
  65.  * relative to the listbox or the button ID.
  66.  */
  67. void Action(WORD wActionCode)
  68. {
  69. int i;
  70. int nLength;
  71. int *pnSelItems;            /* pointer to list of selected items    */
  72. int    nSelCount = GetLBSelCount(hWndList, &pnSelItems);
  73. char szBuffer[100];            /* scratch buffer        */
  74.  
  75.     if (nSelCount < 1)        /* if no items were selected            */
  76.         return;
  77.  
  78.     /* Note: this global value can be overriden in replace.c
  79.      */
  80.     MsWinDoAll = (bOverwrite) ? 1 : 0;
  81.     hSaveCursor = SetCursor(hHourGlass);
  82.     ShowCursor(TRUE);       /* show it      */
  83.  
  84.     /* march through list box checking what's selected
  85.      * and what is not.
  86.      */
  87.     for (i = 0; i < nSelCount ; i++)
  88.     {
  89.         /* extract item from list box...        */
  90.         if ((nLength = (int)SendMessage(hWndList, LB_GETTEXT, 
  91.                             pnSelItems[i], (LONG)(LPSTR)szBuffer)) > 0)
  92.         {
  93.         WORD wIndex = !wFormat ? /* index of filename in buffer */
  94.                 SHORT_FORM_FNAME_INX:LONG_FORM_FNAME_INX;
  95.  
  96.         PSTR pfn = &szBuffer[wIndex]; /* points to filename */
  97.         /* fake arg list for process_zipfile() */
  98.         static char *FileNameVector[] = { "", "" }; 
  99.         
  100.             WinAssert(nLength < (sizeof(szBuffer)-1)); /* DEBUG */
  101.             FileNameVector[0] = pfn;     /* pass desired filename */
  102.             switch (wActionCode) {
  103.             case 0:            /* extract                            */
  104.                 if (SetUpToProcessZipFile(0, 0, 0, 1, 0, 
  105.                                 (int)(bRecreateDirs ? 1 : 0), 
  106.                                 MsWinDoAll, (int)(bTranslate ? 1 : 0),
  107.                                     1, szFileName, FileNameVector))
  108.                     process_zipfile();    /* call into unzip.c        */
  109.  
  110.                 else 
  111.                     MessageBox(hMainWnd, NoMemoryMsg, NULL, 
  112.                                 MB_OK|MB_ICONEXCLAMATION); 
  113.                 
  114.                 TakeDownFromProcessZipFile();    /* clean house    */
  115.                 break;
  116.             case 1:                /* display to message window        */
  117.                 bRealTimeMsgUpdate = FALSE;
  118.                 if (SetUpToProcessZipFile(1, 0, 0, 1, 0,  0, 0, 0,
  119.                                     1, szFileName, FileNameVector))
  120.                     process_zipfile();    /* call into unzip.c        */
  121.  
  122.                 else 
  123.                     MessageBox(hMainWnd, NoMemoryMsg, NULL, 
  124.                                 MB_OK|MB_ICONEXCLAMATION); 
  125.                 
  126.                 TakeDownFromProcessZipFile();    /* clean house    */
  127.                 bRealTimeMsgUpdate = TRUE;
  128.                 UpdateMsgWndPos();                /* update window now */
  129.                 break;
  130.             case 2:                /* test                            */
  131.                 if (SetUpToProcessZipFile(0, 1, 0, 1, 0,  0, 0, 0,
  132.                                     1, szFileName, FileNameVector))
  133.                     process_zipfile();    /* call into unzip.c        */
  134.  
  135.                 else 
  136.                     MessageBox(hMainWnd, NoMemoryMsg, NULL, 
  137.                                 MB_OK|MB_ICONEXCLAMATION); 
  138.                 
  139.                 TakeDownFromProcessZipFile();    /* clean house    */
  140.                 break;
  141.             }
  142.         }
  143.     }
  144.     pnSelItems = (int *)LocalFree((HANDLE)pnSelItems);  /* Returns it to Windows */
  145.     assert(!pnSelItems);    /* DEBUG */
  146.     ShowCursor(FALSE);      /* turn off cursor      */
  147.     SetCursor(hSaveCursor); /* restore the cursor   */
  148.     if (!bIconSwitched)     /* if haven't already, switch icons    */
  149.     {
  150.     HANDLE hIcon;
  151.  
  152.         hIcon = LoadIcon(hInst,"UNZIPPED"); /* load final icon   */
  153.         assert(hIcon);    /* DEBUG */
  154.         SetClassWord(hMainWnd, GCW_HICON, hIcon);
  155.         bIconSwitched = TRUE;    /* flag that we've switched it    */
  156.     }
  157.  
  158. }
  159.  
  160. /* Display the archive comment using the Info-ZIP engine.
  161.  */
  162. void DisplayComment(void)
  163. {
  164.  
  165.     hSaveCursor = SetCursor(hHourGlass);
  166.     ShowCursor(TRUE);       /* show it      */
  167.     bRealTimeMsgUpdate = FALSE;
  168.     if (SetUpToProcessZipFile(0, 0, 0, 1, 1, 0, 0, 0,
  169.                         0, szFileName, NULL))
  170.         process_zipfile();    /* call into unzip.c        */
  171.  
  172.     else 
  173.         MessageBox(hMainWnd, NoMemoryMsg, NULL, 
  174.                     MB_OK|MB_ICONEXCLAMATION); 
  175.     
  176.     TakeDownFromProcessZipFile();    /* clean house    */
  177.     ShowCursor(FALSE);      /* turn off cursor      */
  178.     SetCursor(hSaveCursor); /* restore the cursor   */
  179.     bRealTimeMsgUpdate = TRUE;
  180.     UpdateMsgWndPos();        /* update window now     */
  181. }
  182.